class Incident < ActiveRecord::Base
  belongs_to :computer

  def self.timeout(computer_id)
    incident_count = Incident.find(:all, :conditions => ['computer_id = ? AND resolved_at IS NULL',computer_id]).size
    if incident_count == 0
      Incident.new do |i|
        i.computer_id = computer_id
        i.kind = "DOWN"
        i.data = "Connexion timeout"
      end.save!
    end
  end

end
